package com.kws.merchant.service.impl;


import com.kws.common.config.constant.MinioCommonBucket;
import com.kws.common.security.auth.AuthUtil;
import com.kws.merchant.domain.MerchantAwards;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kws.merchant.mapper.MerchantAwardsMapper;
import com.kws.merchant.service.MerchantAwardsService;
import com.kws.merchant.util.FileUtil;
import com.kws.system.api.domain.SysUser;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;

/**
 * 商家-奖项(MerchantAwards)表服务实现类
 *
 * @author yxy
 * @since 2024-11-01 09:43:21
 */
@Service("merchantAwardsService")
public class MerchantAwardsServiceImpl extends ServiceImpl<MerchantAwardsMapper, MerchantAwards> implements MerchantAwardsService {

    @Resource
    private MerchantAwardsMapper merchantAwardsMapper;
    @Value("${minio.ENDPOINT}")
    private String minioUrl;

    /**
     * 分页查询列表
     */
    @Override
    public Page<MerchantAwards> pageList(com.kws.merchant.domain.po.Page page) {
        Page<MerchantAwards> iPage = new Page<>(page.getPageSize(), page.getTotalPage());
        LambdaQueryWrapper<MerchantAwards> queryWrapper = Wrappers.lambdaQuery();
        SysUser sysUser = AuthUtil.getLoginUser().getSysUser();
        queryWrapper.eq(MerchantAwards::getMerchantId,sysUser.getUserId());
        Page<MerchantAwards> page1 = this.page(iPage, queryWrapper);
        List<MerchantAwards> records = page1.getRecords();
        records.forEach(x->{
            x.setFile(FileUtil.fixFileName()+x.getFile());
        });
        return page1;
    }

    /**
     * 商家奖项新增
     *
     * @param merchantAwards
     * @return
     */
    @Override
    public Object addMerchantAwards(MerchantAwards merchantAwards) {
        Long userId = AuthUtil.getLoginUser().getSysUser().getUserId();
        merchantAwards.setMerchantId(userId);
        merchantAwards.setFile(FileUtil.subFileName(merchantAwards.getFile()));
        return this.save(merchantAwards);
    }


}
